<?php

namespace App\Http\Controllers\Admin\RunTest;

use App\Exceptions\LogicException;
use App\Http\Controllers\Controller;
use App\Models\Api\Apis;
use App\Models\TestApi\TestApi;
use App\Utils\QueryUtil;
use App\Utils\ResUtil;

class TestApiController extends Controller
{

    public function list()
    {
        $request = request()->all();
        $query = TestApi::where(function($query) use($request) {
            QueryUtil::selectBuild($query, $request, [
                ['test_report_uid', '='],
                ['test_module_id', '='],
                ['api_id', '='],
                ['api_name', 'like', 'api_name'],
                ['api', 'like', 'api'],
                ['path', 'like', 'path'],
                ['domain', 'like', 'domain'],
                ['method_type', '='],
                ['status', '='],
                ['id', '='],
            ]);
        });

        $total = $query->count();
        $models = QueryUtil::queryList($query);
        $list = [];
        foreach($models as $i => $v) {
            $list[$i] = $v?->label()?->toArray();
        }
        list($status_maps, $hasMore, $method_type_maps) = [
            TestApi::$status_maps, QueryUtil::hasMore(sizeof($list)), Apis::$method_type_maps
        ];
        return $this->ok(compact('list', 'total', 'hasMore', 'status_maps', 'method_type_maps'));
    }


}
